package com.diamond.webservice.schedule;

import com.diamond.webservice.service.TransmissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;


@Component
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
/**
 * 数据同步定时器
 */
public class TransmissionSchedule {
    @Autowired
    private TransmissionService transmissionService;

    /**
     * 每日同步任务：每日凌晨两点执行任务
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void dailySyncTasks(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
        System.out.println("同步任务开始："+ sdf.format(new Date()));
        transmissionService.transmitManyMain(100);
        System.out.println("同步任务结束："+ sdf.format(new Date()));
    }
}
